﻿Type=StaticCode
Version=5.8
ModulesStructureVersion=1
B4A=true
@EndOfDesignText@
'Code module
'Subs in this code module will be accessible from all modules.
Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.

End Sub
#Region 网络请求
Public Sub doGetReq(cb As Object,jobname As String,url As String,Param() As String)
	Dim hj As HttpJob
	hj.Initialize(jobname,cb)
	If Param==Null Then
		hj.Download(url)
	Else
		hj.Download2(url,Param)
	End If
	AIOHJ(hj)
End Sub
Public Sub doUploadFile(cb As Object,jobname As String,url As String,fn As String)
	Dim hj As HttpJob
	hj.Initialize(jobname,cb)
	Dim lst As List
	lst.Initialize
	Dim fd As MultipartFileData
	fd.Initialize
	fd.KeyName="upfile"
	fd.FileName=fn
	lst.Add(fd)
	hj.PostMultipart(url,Null,lst)
	comm.L("uploadFile:"&fn)
	AIOHJ(hj)
End Sub
'统一处理请求
Private Sub AIOHJ(hj As HttpJob)
	hj.GetRequest.SetHeader("Cookie", readCK)
	If Starter.LocCity.IsInitialized Then
		hj.GetRequest.SetHeader("lat",Starter.LocCity.Latitude)
		hj.GetRequest.SetHeader("lon",Starter.LocCity.Longitude)
		'Log("insert: lat:"&Starter.LocCity.Latitude&" lon:"&Starter.LocCity.Longitude)
	End If
	If Starter.ui.IsInitialized Then'如果用户登录了个人信息就处于已经初始化的状态就发送用户设置的城市，如果没有登陆则发送本次定位到的城市
		hj.GetRequest.SetHeader("city",Starter.ui.city)
	Else if Starter.LocCity.IsInitialized Then
		hj.GetRequest.SetHeader("city",Starter.LocCity.City)
	End If
	Dim ua As String=$"${Application.LabelName}_${Application.PackageName}_${Application.VersionCode}_${Application.VersionName}"$
	hj.GetRequest.SetHeader("User-Agent",ua)
	'Log("UA:"&ua)
	'默认都带cookies
End Sub
'Param:Array as String(key,val,key,val)
'conTyp 默认:application/x-www-form-urlencoded
Public Sub doPostReqArr(cb As Object,jobname As String,url As String,Param() As String,conTyp As String)
	Dim hj As HttpJob
	hj.Initialize(jobname,cb)
	hj.PostString(url,Param2Str(Param))	
	AIOHJ(hj)
	If conTyp=Null Or conTyp.Length<1 Then
		hj.GetRequest.SetContentType("application/x-www-form-urlencoded")
		'hj.GetRequest.SetHeader("Content-Type", "application/x-www-form-urlencoded")'SetContentType("application/x-www-form-urlencoded")
	Else
		hj.GetRequest.SetContentType(conTyp)
		'hj.GetRequest.SetHeader("Content-Type", conTyp)'SetContentType("application/x-www-form-urlencoded")
	End If
End Sub
'Param:Array as String(key,val,key,val)
'conTyp 默认:application/x-www-form-urlencoded
Public Sub doPostReqMap(cb As Object,jobname As String,url As String,m As Map,conTyp As String)
	Dim hj As HttpJob
	hj.Initialize(jobname,cb)
	hj.PostString(url,Param2Str_map(m))	
	AIOHJ(hj)
	If conTyp=Null Or conTyp.Length<1 Then
		hj.GetRequest.SetContentType("application/x-www-form-urlencoded")
		'hj.GetRequest.SetHeader("Content-Type", "application/x-www-form-urlencoded")'SetContentType("application/x-www-form-urlencoded")
	Else
		hj.GetRequest.SetContentType(conTyp)
		'hj.GetRequest.SetHeader("Content-Type", conTyp)'SetContentType("application/x-www-form-urlencoded")
	End If
End Sub
'读取保存的cookie
Private Sub readCK As String
	Dim c As String=g_store.conf.GetDefault("cookie","")
	If c.Length>0 Then
		If c.StartsWith("[") And c.EndsWith("]") Then
			c=c.SubString2(1,c.Length-1)
		End If
	End If
	Log("insertCK:"&c)
	Return c
End Sub
'conTyp 默认:application/x-www-form-urlencoded
Public Sub doPostReqStr(cb As Object,jobname As String,url As String,data As String,contyp As String)
	Dim hj As HttpJob
	hj.Initialize(jobname,cb)
	hj.PostString(url,data)
	'默认都带cookies
	If contyp=Null Or contyp.Length<1 Then
		hj.GetRequest.SetContentType("application/x-www-form-urlencoded")
		'hj.GetRequest.SetHeader("Content-Type", "application/x-www-form-urlencoded")'SetContentType("application/x-www-form-urlencoded")
	Else
		hj.GetRequest.SetContentType(contyp)
		'hj.GetRequest.SetHeader("Content-Type", conTyp)'SetContentType("application/x-www-form-urlencoded")
	End If
	AIOHJ(hj)
End Sub
'加入url encode
public Sub Param2Str(str() As String) As String
	Dim ret,retorg As String
	For i=0 To str.Length/2-1
		ret=ret&$"${str(i*2)}=${comm.urlencode(str(i*2+1))}&"$
		retorg=retorg&$"${str(i*2)}=${str(i*2+1)}&"$
	Next
	ret=ret.SubString2(0,ret.Length-1)
	'Log("par2str:"&ret)
	Log("par2strOrg:"&retorg)
	Return ret
End Sub
public Sub Param2Str_map(m As Map) As String
	Dim ret,retorg As String
	For i=0 To m.Size-1
		ret=ret&$"${m.GetKeyAt(i)}=${comm.urlencode(m.GetValueAt(i))}&"$
		retorg=retorg&$"${m.GetKeyAt(i)}=${comm.urlencode(m.GetValueAt(i))}&"$
	Next
	ret=ret.SubString2(0,ret.Length-1)
	'Log("par2str:"&ret)
	Log("par2strOrg:"&retorg.SubString2(0,retorg.Length-1))
	Return ret
End Sub
public Sub getStatusData(str As String) As netRes
	Dim ret As netRes
	ret.Initialize
	Try
		Dim jsp As JSONParser
		jsp.Initialize(str)
		Dim root As Map	= jsp.NextObject 
		If root.ContainsKey("status") Then
			ret.nCode=root.GetDefault("status",200)
			ret.sData=root.Get("data")
		Else
			ret.nCode=200
		End If
	Catch
		ret.nCode=400
		ret.sData=LastException.Message
	End Try
	Return ret
'	If str.IndexOf("status")>-1 Then
'		Try
'			Dim parser As JSONParser 
'			parser.Initialize(str) 
'			Dim root As Map = parser.NextObject 
'			If root.ContainsKey("status") Then
'				'Dim data As String = root.Get("data") 
'				Dim status As String = root.Get("status") 
'				ret.nCode=status
'				'ret.sData=data	
'				Return ret
'			Else'如果没有status就直接判断成功
'				ret.nCode=200
'				'ret.sData=""
'				Return ret
'			End If
'		Catch
'			Log("getStatusData:"&LastException.Message)
'		End Try
'	Else'如果没有status就直接判断成功
'		ret.nCode=200
'		ret.sData=""
'		Return ret
'	End If
'	Return Null
End Sub
'支持直接更新
public Sub updateCookie(m As Map) As String
	Dim c As String=m.GetDefault("Set-Cookie","")
	Dim a As Int=c.IndexOf("kaopu_cookiename")
	Dim b As Int=c.IndexOf2(";",a+1)
	c=c.SubString2(a,b+1)
	If c.Length>0 Then
		 Log("cookie updated val:"&c)
		 g_store.conf.Put("cookie",c)
	End If
	Return c
End Sub
#End Region
#Region 解析类

Public Sub parseJinqi(str As String) As List
	Dim parser As JSONParser 
	parser.Initialize(str) 
	Dim root As Map = parser.NextObject 
	Dim data As List = root.Get("data") 
	Dim ret As List
	ret.Initialize
	For Each coldata As Map In data 
	    Dim into_money As String = coldata.Get("into_money") 
	    Dim city As String = coldata.Get("city") 
	    Dim keshi As String = coldata.Get("keshi") 
	    Dim remark As String = coldata.Get("remark") 
	    Dim time As String = coldata.Get("time") 
	    Dim usertel As String = coldata.Get("usertel") 
	    Dim order_id As String = coldata.Get("order_id") 
	    Dim nianji As String = coldata.Get("nianji") 
	    Dim hy_school As String = coldata.Get("hy_school") 
	    Dim username As String = coldata.Get("username") 
		Dim image As String = coldata.Get("image") 
		Dim jq As Jinqi
		jq.Initialize
		jq.evalStr=remark
		jq.sendby.Initialize
		jq.sendby.grade=nianji
		jq.sendby.name=username
		jq.sendby.school=hy_school
		jq.sendby.img=image
		jq.sendby.keshi=keshi
		jq.price=into_money
		jq.sDate=time
		ret.Add(jq)
	Next 
	Return ret

End Sub
Public Sub parseFavTeacher(str As String) As List
	Dim parser As JSONParser 
	parser.Initialize(str) 
	Dim root As Map = parser.NextObject 
	Dim status As Int = root.Get("status") 
	If status=200 Then
		Dim data As List = root.Get("data") 
		Dim lst As List
		lst.Initialize
		For Each coldata As Map In data 
		    Dim image As String = coldata.Get("image") 
		    Dim stu_c As String = coldata.Get("stu_c") 
		    Dim fl_title As String = coldata.Get("fl_title") 
		    Dim sex As String = coldata.Get("sex") 
		    Dim hpz_c As String = coldata.Get("hpz_c") 
		    Dim juli As String = coldata.Get("juli") 
		    Dim js_id As String = coldata.Get("js_id") 
		    Dim id As String = coldata.Get("id") 
		    Dim hp_c As String = coldata.Get("hp_c") 
		    Dim hp_lv As String = coldata.Get("hp_lv") 
		    Dim seniority As String = coldata.Get("seniority") 
		    Dim username As String = coldata.Get("username") 
			Dim favtec As Teacher
			'favtec.adWords=
			favtec.rateNum=hpz_c
			favtec.distence=juli
			favtec.headimg=comm.combinPic(image)
			favtec.teacheAge=seniority
			favtec.nickname=username
			favtec.ratePercent=hp_lv
			favtec.stunum=stu_c
			'favtec.ID=id
			favtec.ID=js_id
			lst.Add(favtec)
		Next 
		'g_store.conf.Put("favteclst",lst)
		Return lst
	Else
		Return Null
	End If
End Sub
Public Sub parseYhq(str As String) As Boolean
	Dim parser As JSONParser 
	parser.Initialize(str) 
	Dim root As Map = parser.NextObject 
	Dim status As Int = root.Get("status") 
	If status=200 Then
		Dim data As List = root.Get("data") 
		Dim lst As List
		lst.Initialize
		For Each coldata As Map In data 
		    Dim start_time As String = coldata.Get("start_time") 
		    'Dim is_status As String = coldata.Get("is_status") 
		    Dim quan_money As String = coldata.Get("quan_money") 
		    'Dim quan_hao As String = coldata.Get("quan_hao") 
			Dim quan_name As String = coldata.Get("quan_name") 
		    Dim xz_money As String = coldata.Get("xz_money") 
		    Dim quan_id As String = coldata.Get("quan_id") 
		    Dim end_time As String = coldata.Get("end_time") 
		    Dim is_xz As Int = coldata.Get("is_xz") 
		    'Dim is_yong As String = coldata.Get("is_yong") 
			Dim yhq As yhq
			yhq.Initialize
			yhq.yhqname=quan_name
			yhq.starttime=start_time
			yhq.endtime=end_time
			yhq.money=quan_money
			yhq.yhdid=quan_id
			If is_xz=1 Then
				yhq.withLimit=True 
				yhq.uselimit=xz_money
			Else 
				yhq.withLimit=False
				yhq.uselimit=0
			End If
			lst.Add(yhq)
		Next 
		g_store.conf.Put("yhqlst",lst)'存到数据库
		Return True
	End If
	Return False
End Sub
Public Sub parseMyInfo(str As String) as myInfo
	Dim parser As JSONParser 
	parser.Initialize(str) 
	Log(str)
	Dim root As Map = parser.NextObject
	Dim data As Map = root.Get("data") 
	Dim image As String = data.Get("image") 'headimage
	Dim address As String = data.Get("address") 
	Dim coordinate As String = data.Get("coordinate") 
	'Dim last_login_time As String = data.Get("last_login_time") 
	Dim city As String = data.Get("city") 
	Dim sex As String = data.Get("sex") 
	'Dim locking As String = data.Get("locking") 
	'Dim photo As String = data.Get("photo") 
	Dim autograph As String = data.Get("autograph") 
	Dim usertel As String = data.Get("usertel") 
	Dim nianji As String = data.Get("nianji") 
	'Dim login_ip As String = data.Get("login_ip") 
	Dim hy_school As String = data.Get("hy_school") 
	'Dim uid As String = data.Get("uid") 
	'Dim addtime As String = data.Get("addtime") 
	Dim hy_id As String = data.Get("hy_id") 
	'Dim edittime As String = data.Get("edittime") 
	Dim age As String = data.Get("age") 
	Dim username As String = data.Get("username") 
	Dim ordnum As Int = data.Get("c") 
	Dim yhq As Int = data.Get("yhc") 
	Dim favteacher As Int = data.Get("gc") 
	Dim money As String = data.Get("money") 
	Dim qqid As String = data.Get("qqid")
	Dim openid As String = data.Get("openid") 
	Dim jpush_pwd As String = data.Get("jpush_pwd") 
	Dim mi As myInfo
	mi.Initialize
	mi.school=hy_school
	mi.yhqNum=yhq
	mi.ordNum=ordnum
	mi.qqid=qqid
	mi.jpush_pwd=jpush_pwd
	mi.wxid=openid
	mi.favTeacherNum=favteacher
	mi.yue=money
	mi.city=city
	mi.address=address
	mi.age=age
	mi.commit=autograph
	mi.grade=nianji
	mi.uid=hy_id
	mi.nickname=username
	If image.Length>4 Then 
		mi.headimg=image
	Else
		mi.headimg=comm.S_TESTMYHEADER
	End If
	mi.usertel=usertel
	If sex.EqualsIgnoreCase("1") Then
		mi.sex="男"
	Else
		mi.sex="女"
	End If
	mi.jwd=coordinate
	g_store.conf.Put("myinfo",mi)
	return mi
End Sub
public Sub parseKemu(str As String) As List
	Dim parser As JSONParser 
	parser.Initialize(str) 
	Dim root As Map = parser.NextObject
	Dim data As List=root.Get("data")
	Dim lst As List
	lst.Initialize
	For Each colroot As Map In data 
		Dim st As Subject
		st.Initialize
		st.name=colroot.Get("fl_title")
		st.img=comm.combinPic(colroot.Get("fl_img"))				
		st.id = colroot.Get("fl_id")
		lst.Add(st)
	Next 
	Return lst
End Sub
public Sub parseBanner(str As String) As List
	Dim parser As JSONParser 
	parser.Initialize(str) 
	Dim root As Map = parser.NextObject
	Dim bannerlist As List
	bannerlist.Initialize
	Dim data As List = root.Get("data") 
	For Each colroot As Map In data
		bannerlist.Add(comm.combinPic(colroot.Get("url") ))
	Next 
	Return bannerlist
End Sub
'Public Sub parseCityRegion(str As String) As List
'	Dim parser As JSONParser 
'	parser.Initialize(str) 
'	Dim root As Map = parser.NextObject 
'	Dim data As Map = root.Get("data") 
'	Dim 1 As Map = data.Get("1") 
'	Dim children As List = 1.Get("children") 
'	For Each colchildren As Map In children 
'	    Dim parent_id As String = colchildren.Get("parent_id") 
'	    Dim region_id As String = colchildren.Get("region_id") 
'	    Dim region_name As String = colchildren.Get("region_name") 
'	Next 
'	Dim parent_id As String = 1.Get("parent_id") 
'	Dim region_id As String = 1.Get("region_id") 
'	Dim region_name As String = 1.Get("region_name") 
'	Dim 14 As Map = data.Get("14") 
'	Dim parent_id As String = 14.Get("parent_id") 
'	Dim region_id As String = 14.Get("region_id") 
'	Dim region_name As String = 14.Get("region_name") 
'	Dim 10 As Map = data.Get("10") 
'	Dim parent_id As String = 10.Get("parent_id") 
'	Dim region_id As String = 10.Get("region_id") 
'	Dim region_name As String = 10.Get("region_name") 
'	Dim status As String = root.Get("status") 
'	
'End Sub


'将json string 解析成 teacher list对象
public Sub parseTeacher(str As String) As List
	Dim parser As JSONParser 
	parser.Initialize(str) 
	Dim root As Map = parser.NextObject 
	Dim data As List = root.Get("data") 
	Dim retlst As List
	retlst.Initialize
	For Each coldata As Map In data 
	    Dim note As String = coldata.GetDefault("note","") 
	    Dim city As String = coldata.GetDefault("city","") 
	    Dim is_user_note As String = coldata.GetDefault("is_user_note","") 
	    Dim keshi As String = coldata.GetDefault("keshi","") 
	    Dim is_xw As String = coldata.GetDefault("is_xw","") 
	    Dim autograph As String = coldata.GetDefault("autograph","") 
	    Dim is_xw_note As String = coldata.GetDefault("is_xw_note","") 
	    Dim usertel As String = coldata.GetDefault("usertel","") 
	    Dim experience As String = coldata.GetDefault("experience","") 
	    Dim shenfen_hou_photo As String = coldata.GetDefault("shenfen_hou_photo","") 
	    Dim hp_lv As String = coldata.GetDefault("hp_lv","") 
	    Dim stu_c As String = coldata.GetDefault("stu_c","") 
	    Dim is_zs As String = coldata.GetDefault("is_zs","") 
	    Dim shenfen_photo As String = coldata.GetDefault("shenfen_photo","") 
	    Dim fl_title As String = coldata.GetDefault("fl_title","") 
	    Dim fmode As String = coldata.GetDefault("fmode","") 
	    Dim js_id As String = coldata.GetDefault("js_id","") 
	    Dim id As String = coldata.GetDefault("id","") 
	    Dim hp_c As String = coldata.GetDefault("hp_c","") 
	    Dim is_user As String = coldata.GetDefault("is_user","") 
	    Dim cert_zs_photo As String = coldata.GetDefault("cert_zs_photo","") 
	    Dim is_zg As String = coldata.GetDefault("is_zg","") 
	    Dim image As String = coldata.GetDefault("image","") 
	    Dim js_xj As String = coldata.GetDefault("js_xj","") 
	    Dim address As String = coldata.GetDefault("address","") 
	    Dim sex As String = coldata.GetDefault("sex","") 
	    Dim locking As String = coldata.GetDefault("locking","") 
	    Dim photo As String = coldata.GetDefault("photo","") 
	    Dim is_zs_note As String = coldata.GetDefault("is_zs_note","") 
	    Dim shenfen_qian_photo As String = coldata.GetDefault("shenfen_qian_photo","") 
	    Dim quyu As String = coldata.GetDefault("quyu","") 
	    Dim cert_zg_photo As String = coldata.GetDefault("cert_zg_photo","") 
	    Dim addtime As String = coldata.GetDefault("addtime","") 
	    Dim grade As String = coldata.GetDefault("grade","") 
	    Dim is_sh As String = coldata.GetDefault("is_sh","") 
	    Dim hpz_c As String = coldata.GetDefault("hpz_c","") 
	    Dim juli As String = coldata.GetDefault("juli","") 
		Dim money As String = coldata.GetDefault("money","") 
	    Dim is_zg_note As String = coldata.GetDefault("is_zg_note","") 
	    Dim cert_xw_photo As String = coldata.GetDefault("cert_xw_photo","") 
	    Dim seniority As String = coldata.GetDefault("seniority","") 
	    Dim username As String = coldata.GetDefault("username","") 
	    Dim is_tuijian As String = coldata.GetDefault("is_tuijian","") 
		Dim t As Teacher
		t.Initialize
		t.ID=id
		If t.ID.Length<1 Then t.ID=js_id
		t.nickname=username
		t.distence=juli
		t.headimg=comm.combinPic(image)
		t.adWords=autograph
		t.rateNum=hpz_c
		t.ratePercent=hp_lv
		t.realname=username
		If sex.EqualsIgnoreCase("1") Then
			t.sexMen=True
		Else
			t.sexMen=False
		End If
		t.startPrice=money
		t.stunum=stu_c
		t.teacheAge=seniority
		retlst.Add(t)
	Next 
	Return retlst

End Sub
#End Region

